<?php
namespace Chat\Controller;
use Think\Controller;
class UploadController extends Controller{

    public function upload(){
        $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize   =     3145728 ;// 设置附件上传大小
        $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
        $upload->rootPath  =     'Public/upload/image/'; // 设置附件上传根目录
        $upload->savePath  =     ''; // 设置附件上传（子）目录
        // 上传文件 
        $info   =   $upload->uploadOne(reset($_FILES));
        if(!$info) {// 上传错误提示错误信息
            $this->ajaxReturn(['status'=>0, 'msg'=>$upload->getError()]);
        }else{// 上传成功
            $path = '/'.$upload->rootPath.$info['savepath'].$info['savename'];
            $this->ajaxReturn(['status'=>1, 'msg'=>'上传成功！', 'path'=>$path]);
        }
    }
}